package bch.maven.plugin.guava;

import com.google.common.collect.ForwardingList;
import java.util.ArrayList;
import java.util.List;

public class LoggingList<E> extends ForwardingList<E> {

    private final List<E> delegate;

    public LoggingList(List<E> delegate) {
        this.delegate = delegate;
    }

    @Override
    protected List<E> delegate() {
        return delegate;
    }

    @Override
    public boolean add(E element) {
        System.out.println("[LOG] Adding element: " + element);
        return super.add(element);
    }

    @Override
    public boolean addAll(java.util.Collection<? extends E> collection) {
        System.out.println("[LOG] Adding collection: " + collection);
        return super.addAll(collection);
    }

    @Override
    public E remove(int index) {
        System.out.println("[LOG] Removing element at index: " + index);
        return super.remove(index);
    }

    public static void main(String[] args) {
        List<String> list = new LoggingList<>(new ArrayList<>());
        list.add("apple");
        list.add("banana");
        list.remove(0);

        System.out.println("Final list: " + list);
    }
}
